package YNU.View.impl;

import YNU.View.TeacherView;
import YNU.dao.StudentDao;
import YNU.dao.TeacherDao;
import YNU.dao.impl.StudentDaoImpl;
import YNU.dao.impl.TeacherDaoImpl;
import YNU.po.Student;
import YNU.po.Teacher;


import java.util.List;
import java.util.Scanner;

public class TeacherViewImpl implements TeacherView {

    private Scanner input = new Scanner(System.in);

    @Override
    public Teacher login() {
        System.out.println("请输入管理员(老师)名称：");
        String cname = input.next();
        System.out.println("请输入密码：");
        String password = input.next();

        TeacherDao dao = new TeacherDaoImpl();
        return dao.getTeacherByNameByPass(cname, password);
    }
    public void saveTeacher(){

        System.out.println("请输入管理员(老师)名称：");
        String name = input.next();
        System.out.println("请输入管理员(老师)密码：");
        int password = input.nextInt();
        TeacherDao dao = new TeacherDaoImpl();
        int sid = dao.saveTeacher(name,password);
        if(sid>0) {
            System.out.println("新建管理员(老师)成功！管理员(老师)编号为："+sid);
        }else {
            System.out.println("新建管理员(老师)失败！");
        }

    }
    public void listTeacherAll(){
        TeacherDao dao = new TeacherDaoImpl();
        List<Teacher> list = dao.listTeacher(null,null);
        System.out.println("编号\t名称\t密码");
        for(Teacher b : list) {
            System.out.println(b.getCid()+"\t"+b.getCname()+"\t"+b.getPassword());
        }
    }
    public void removeTeacher(){
        System.out.println("请输入管理员编号：");
        int sid = input.nextInt();

        TeacherDao dao = new TeacherDaoImpl();

        int result = dao.removeTeacher(sid);
        if(result==1) {
            System.out.println("删除管理员成功！");
        }else {
            System.out.println("删除管理员失败！");
        }
        //}
    }


}
